import { ref } from 'vue'
import { defineStore } from 'pinia'

export const loginState = defineStore('loginState', {

  state: () => {
    return {
      isLoginState: true,
      isTryingLogin: false
    }
  },
  actions: {
    turnLoginStateToTrue() {
      this.isLoginState = true
    },
    turnLoginStateToFalse() {
      this.isLoginState = false
    },

    isTryingLoginOfTrue() {
      this.isTryingLogin = true
    },
    isTryingLoginOfFalse() {
      this.isTryingLogin = false
    }
  },
  persist: {
    enabled: true, // 开启缓存 localstorage/sessionStorage
    storage: sessionStorage, // 缓存使用方式
    paths:['isLoginState', 'isTryingLogin'] // 需要缓存键
  }

  // // 登陆状态
  // const isLoginState = ref(false)
  // const turnLoginStateToTrue = () => {
  //   isLoginState.value = true
  // }
  // const turnLoginStateToFalse = () => {
  //   isLoginState.value = false
  // }

  // // 是否显示userBar界面
  // const isTryingLogin = ref( !isLoginState.value )
  // const isTryingLoginOfTrue = () => {
  //   isTryingLogin.value = true
  // }
  // const isTryingLoginOfFalse = () => {
  //   isTryingLogin.value = false
  // }

  // return {
  //   isLoginState,turnLoginStateToTrue,turnLoginStateToFalse,
  //   isTryingLogin,isTryingLoginOfTrue,isTryingLoginOfFalse
  // };
})
